package com.example.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.model.MailInfo;
import com.example.demo.service.MailService;

@RestController
public class MailController {
	@Autowired
	private MailService mailService;

	/**
	 * send简单邮件
	 * @param m
	 * @param request
	 */
	@RequestMapping(value = "/SendSimpleMail", method = RequestMethod.POST)
	public void sendSimpleMail(@RequestBody MailInfo m, HttpServletRequest request) {
		mailService.sendSimpleMail(m.getRecipient(), m.getTheme(), m.getContent());
	}

	/**
	 * send带附件的邮件
	 * @param m
	 * @param request
	 */
	@RequestMapping(value = "/sendAttachmentsMail", method = RequestMethod.POST)
	public void sendAttachmentsMail(@RequestBody MailInfo m, HttpServletRequest request) {
		mailService.sendAttachmentsMail(m.getRecipient(), m.getTheme(), m.getContent(), m.getAttachmentPath());
	}

	/**
	 * send带静态资源的邮件
	 * @param m
	 * @param request
	 */
	@RequestMapping(value = "/sendInlineResourceMail", method = RequestMethod.POST)
	public void sendInlineResourceMail(@RequestBody MailInfo m, HttpServletRequest request) {
		String rscId = "rscId001";
		mailService.sendInlineResourceMail(m.getRecipient(), m.getTheme(),
				"<html><body>" + m.getContent() + "<img src=\'cid:" + rscId + "\' ></body></html>",
				m.getAttachmentPath(), rscId);
	}
}
